package org.example;

import org.example.bo.StudentInfo;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Classname StreamSortExample
 * @Description TODO
 * @Date 2020/10/28 4:17 下午
 * @Created by xiangjd
 */
public class StreamSortExample {
    public static void main(String[] args) {
        //测试数据，请不要纠结数据的严谨性
        List<StudentInfo> studentList = new ArrayList<>();
        studentList.add(new StudentInfo("李小明", true, 18, 1.76, LocalDate.of(2001, 3, 23)));
        studentList.add(new StudentInfo("张小丽", false, 18, 1.61, LocalDate.of(2001, 6, 3)));
        studentList.add(new StudentInfo("王大朋", true, 19, 1.82, LocalDate.of(2000, 3, 11)));
        studentList.add(new StudentInfo("陈小跑", false, 17, 1.67, LocalDate.of(2002, 10, 18)));

        StudentInfo.printStudents(studentList);

        List<StudentInfo> collect1 = studentList.stream().sorted(Comparator.comparing(StudentInfo::getAge)).collect(Collectors.toList());
//        StudentInfo.printStudents(collect1);

        List<StudentInfo> collect2 = studentList.stream().sorted(Comparator.comparing(StudentInfo::getAge).reversed()).collect(Collectors.toList());
//        StudentInfo.printStudents(collect2);

        List<StudentInfo> collect3 = studentList.stream().sorted(Comparator.comparing(StudentInfo::getAge).thenComparing(StudentInfo::getHeight)).collect(Collectors.toList());
        StudentInfo.printStudents(collect3);

        ArrayList<String> strings = new ArrayList<>();
        strings.add("1");
        strings.add("3");
        strings.add("2");
        List<String> sortStrings = strings.stream().sorted().collect(Collectors.toList());
        System.out.println(sortStrings);

        List<String> collect4 = strings.stream().sorted((a, b) -> {
            int i = a.compareTo(b);
            return i;
        }).collect(Collectors.toList());
        System.out.println(collect4);


    }
}
